<template>
  <div class="dashboard-container">
    <div class="app-container">
      <el-card shadow="never">
        <el-table
          :key="tableKey"
          :data="dataList"
          v-loading="listLoading"
          element-loading-text="加载中"
          fit
          highlight-current-row
          style="width:100%"
          border
        >
          <el-table-column type="index" label="序号" width="100"></el-table-column>
          <el-table-column align="center" label="机构名称">
            <template slot-scope="scope">
              <span>{{scope.row.name}}</span>
            </template>
          </el-table-column>
          <el-table-column align="center" label="申请人">
            <template slot-scope="scope">
              <span>{{scope.row.name}}</span>
            </template>
          </el-table-column>
          <el-table-column align="center" label="申请时间">
            <template slot-scope="scope">
              <span>{{scope.row.createDate | dateformat('YYYY-MM-DD HH:mm:ss')}}</span>
            </template>
          </el-table-column>
          <el-table-column align="center" label="机构状态">
            <template>
              <span>正常</span>
            </template>
          </el-table-column>
          <!-- 操作按钮 -->
          <el-table-column
            align="center"
            label="操作"
            width="200"
            class-name="small-padding fixed-width"
          >
            <template slot-scope="scope">
              <el-link
                type="primary"
                :underline="false"
                @click="handleDetail(scope.row.companyId)"
              >资料</el-link>&nbsp;&nbsp;
              <el-link
                type="primary"
                :underline="false"
                @click="handleCourse(scope.row.companyId)"
              >课程</el-link>
              <!--              &nbsp;&nbsp;
              <el-link type="primary"
                      :underline="false"
                      @click="handleStatus(scope.row.courseBaseId)">
                      订单
              </el-link>
              &nbsp;&nbsp;
              <el-link type="danger"
                      :underline="false"
                      @click="handleForbidden(scope.row.courseBaseId)">
                      封禁
              </el-link>-->
            </template>
          </el-table-column>
        </el-table>
        <!-- end -->
        <!-- 分页 -->
        <div class="pagination">
          <div class="pages" style="float: right;margin-bottom: 20px;">
            <el-pagination
              background
              @size-change="handleSizeChange"
              @current-change="handleCurrentChange"
              :current-page="Number(requestParameters.pageNo)"
              :total="Number(total)"
              :page-size="Number(requestParameters.pageSize)"
              :page-sizes="[10,20,30,50]"
              layout="sizes, prev, pager, next, jumper"
            ></el-pagination>
          </div>
        </div>
        <!-- end -->
        <!-- 新增标签弹层 -->
        <coureseDialog
          ref="auditCourse"
          :titleInfo="titleInfo"
          :formBase="formData"
          @newDataes="getList"
        ></coureseDialog>
      </el-card>
    </div>
  </div>
</template>
<script>
import { list } from '@/api/xczx/institutions'
import coureseDialog from './../components/course-audit'
var _this = null
export default {
  name: 'Courses',
  components: {
    coureseDialog
  },
  data() {
    return {
      audiStatus: '已提交',
      tableKey: 0,
      dataList: [],
      total: null,
      listLoading: true,
      alertText: '',
      requestParameters: {
        pageNo: 1,
        pageSize: 10
      },
      requestBody: {},
      titleInfo: {
        pageTitle: '',
        text: ''
      },
      formData: {
        isFamous: '',
        shortName: '',
        company: '',
        tags: '',
        remarks: ''
      }
    }
  },
  computed: {
    status() {
      return status
    }
  },
  methods: {
    // 初始数据
    initialDate() {
      // 读取数据
      this.getList()
    },
    // 获取列表数据
    async getList(params) {
      this.listLoading = true
      this.requestBody.approvalStatus = this.NET.INSTIUTIONS_THROUGH
      const { data: res } = await list(this.requestParameters, this.requestBody)
      // 获取数据给dataList
      this.dataList = res.items
      // 获取总条数
      this.total = res.counts
      this.alertText = `共 ${this.total} 条记录`
      this.listLoading = false
    },
    // 重置
    resetForm() {
      this.$refs['requestParameters'].resetFields()
    },
    // 每页显示信息条数
    handleSizeChange(val) {
      this.requestParameters.pageSize = val
      if (this.requestParameters.pageNo === 1) {
        this.getList(this.requestParameters)
      }
    },
    // 进入某一页
    handleCurrentChange(val) {
      this.requestParameters.pageNo = val
      this.getList()
    },
    // **********************************
    // 搜索的项目
    // 添加、编辑之后表单清空
    query() {
      this.formData = {}
    },
    // 查看机构详情
    handleDetail(companyid) {
      this.$router.push({
        path: '/institutions/insdetail',
        query: { companyId: companyid }
      })
    },
    // 查看机构课程
    handleCourse(companyid) {
      this.$router.push({
        path: '/courses/list',
        query: { companyId: companyid }
      })
    },
    // 窗口操作**********************************
    // 封禁机构
    async handleForbidden(objeditId) {
      this.$confirm('确定要封禁该机构?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'info'
      })
        .then(() => {
          this.$message({
            type: 'success',
            message: '封禁成功!'
          })
        })
        .catch(() => {
          this.$message({
            type: 'info',
            message: '已取消'
          })
        })
    },
    // 启用、禁用
    handleStatus(val) {
      var status = ''
      if (val.state === true) {
        val.state = 0
        status = '禁用'
      } else {
        val.state = 1
        status = '启用'
      }
      var data = {
        id: val.id,
        state: val.state
      }
      this.$confirm('已成功' + status + ', 是否继续?', '提示', {
        type: 'warning'
      })
        .then(async () => {
          await disabled(data)
            .then(response => {
              this.$message.success('已成功' + status + '!')
              this.getList(this.requestParameters)
            })
            .catch(response => {
              this.$message.error(status + '失败!')
            })
        })
        .catch(() => {
          this.$message.info('已取消操作!')
        })
    }
  },
  // 挂载结束
  mounted: function() {},
  // 创建完毕状态
  created() {
    var _this = this
    this.initialDate()
    // 键盘enter操作
    document.onkeydown = function(e) {
      var key = window.event.keyCode
      if (key === 13) {
        _this.handleFilter(this.requestParameters)
      }
    }
  },
  // 组件更新
  updated: function() {}
}
</script>
<style rel="stylesheet/scss" lang="scss" scoped>
.alert {
  margin: 10px 0px;
}
.pagination {
  margin-top: 10px;
}
</style>
<style>
.el-table th {
  background-color: #ffffff;
}
.el-table th.is-leaf {
  border-bottom: 2px solid #e8e8e8;
}
.disabled td {
  background-color: #f9f9f9;
  color: #c1c1c1;
}
.disabled .el-button--primary,
.disabled .el-button--danger {
  background-color: #dbdada;
  border: 1px solid #dbdada;
  color: #999;
  cursor: not-allowed;
}
</style>
